


import java.applet.*; 
import java.awt.*; 
import java.awt.event.*; 
import java.net.*; 
import javax.media.*; 

public class PlayerApplet extends Applet implements ControllerListener 
{ 
Player player = null; 
public void init() 
{ 
setLayout(new BorderLayout()); 
String mediaFile = 

"rtsp://lillestroem.uio.no/div/imk/strekktekst/320/L1M2.mp4";; 

mediaFile = "c://testcam.avi"; 

try 
{ 

MediaLocator mrl= new MediaLocator(mediaFile); 


player = Manager.createRealizedPlayer(mrl); 
System.out.println( "player created" ); 
player.addControllerListener(this); 
} 
catch ( Exception e ) 
{ 
System.err.println("Got exception "+e); 
} 
} 
public void start() 
{ 
player.start(); 
System.out.println( "player started" ); 

} 
public void stop() 
{ 
player.stop(); 
player.deallocate(); 
} 
public void destroy() 
{ 
player.close(); 
} 

public synchronized void controllerUpdate(ControllerEvent event) 
{ 
System.out.println( "player event" + event ); 

if ( event instanceof RealizeCompleteEvent ) 
{ 
Component comp; 
if ( (comp = player.getVisualComponent()) != null ) 
add ("Center", comp); 
if ( (comp = player.getControlPanelComponent()) != null ) 
add ("South", comp); 
validate(); 
} 
} 

/** 
* Allow this Applet to run as as application as well. 
* 
* @param args 
* command line arguments ignored. 
*/ 
public static void main ( String args[] ) 
{ 
final PlayerApplet applet = new PlayerApplet(); 
Frame frame = new Frame( "JMF Player" ); 
frame.setSize( 100, 100 ); 
applet.init(); 
frame.add( applet ); 
frame.validate(); 
frame.setVisible( true ); 
applet.start(); 
frame.addWindowListener( new WindowAdapter() 
{ 

/** 
* Handle request to shutdown. 
* 
* @param e 
* event giving details of 
closing. 
*/ 
public void windowClosing ( 
WindowEvent e ) 
{ 
applet.stop(); 
applet.destroy(); 
System.exit( 0 ); 
} // end WindowClosing 
} // end anonymous class 
); // end addWindowListener line 
} // end main 

} 

